<?php header('Content-Type:text/html;charset=utf-8');?>

<?php $htaccess = false; ?>
<?php
    $pagesize = 11;
    if($_SERVER['REQUEST_METHOD']=="GET")
    {
        $pageindex = $_GET['pageindex'];
        if($pageindex=='')
        {
            $pageindex = 0;
        }
    }
?>

<!DOCTYPE html>
<head>
    <title>我的日记</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>

<?php

    require_once("mysql_config.php");

    $db = new PDO("mysql:host={$dbhost};dbname={$dbname}","{$dbuid}","{$dbpwd}");
    $sql = "SELECT * FROM _Article limit ".($pageindex*$pagesize).",".($pagesize+1);
    $db->query("set names utf8;");
    $rs = $db->query($sql);
    $row = $rs->fetchAll(PDO::FETCH_ASSOC);

    foreach($row as $r)
    {
            $countid++;
            echo "<div>\r\n";
            if($htaccess)
            {
                echo "<a href='".$r['_sid'].".html'>".$r['_title']."[".$r['_date']."]</a>\r\n";
            }
            else
            {
                echo "<a href='article_viewthread.php?id=".$r['_sid']."'>".$r['_title']."[".$r['_date']."]</a>\r\n";
            }
            echo "<p>".$r['_body']."</p>\r\n";
            echo "</div>\r\n";
        
    }
    
    if($pageindex==0)
    {
        if($pagesize+1 == $countid)
        {
            if($htaccess)
            {
                echo "<a href='p_".($pageindex+1).".html'>首页,下一页</br>";
            }
            else
            {
                echo "<a href='?pageindex=".($pageindex+1)."'>首页,下一页</br>";
            }
        }
    }
    elseif($pagesize!=$countid)
    {
        if($htaccess)
        {
             echo "<a href='p_".($pageindex-1).".html'>末页,上一页</br>";
        }
        else
        {
            echo "<a href='?pageindex=".($pageindex-1)."'>末页,上一页</br>";
        }
    }
    else
    {
        if($htaccess)
        {
            echo "<a href='p_".($pageindex-1).".html'>上一页</br>";
            echo "<a href='p_".($pageindex+1).".html'>下一页</br>";
        }
        else
        {
            echo "<a href='?pageindex=".($pageindex-1)."'>上一页</br>";
            echo "<a href='?pageindex=".($pageindex+1)."'>下一页</br>";
        }
    }
?>

</body>
</html>
